﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using BL.Abstract;
using BL.Managers;
using NHibernate;

namespace DBContract.Domain
{
    public class RepositoryFactory : IRepositoryFactory
    {
        #region Fields

        private readonly ISession _session;

        #endregion

        #region Constructors

        public RepositoryFactory(ISession session)
        {
            _session = session;
        }

        #endregion

        #region IRepositoryFactory Members

        public IDBManager<T> Get<T>() where T : class
        {
            return new DBManager<T>(_session);
        }

        public void Clear()
        {
            _session.Clear();
        }

        #endregion

        #region IDisposable Members

        public void Dispose()
        {
            _session.Close();
            _session.Dispose();
        }

        #endregion
    }

}
